package com.xq.springboot.controller;

import com.xq.springboot.pojo.People;
import com.xq.springboot.utils.ResultObj;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author xq
 * @version 1.0
 * @date 2021/4/18 19:13
 * @description 人们控制器
 */
@RestController
@RequestMapping("user")
@Api(description = "人们管理控制器", value = "PeopleController")
public class PeopleController {
    /**
     * 添加人们
     * @param people 人们对象
     * @return 返回Http状态
     */
    @ApiOperation(value = "添加人们")
    @PostMapping("addPeople")
    public ResultObj addPeople(@RequestBody People people) {
        // @RequestBody验证前端所有数据非空的同时要求必须提交json格式的数据
        System.out.println(people);
        return new ResultObj(200,"添加成功");
    }

    /**
     * 添加人们2
     * @param people
     * @return
     */
    @ApiOperation(value = "添加人们2")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id",value = "人们标识",required = true,paramType = "整数",dataType = "整数"),
            @ApiImplicitParam(name = "name",value = "人们姓名",required = true,paramType = "字符串",dataType = "字符串"),
            @ApiImplicitParam(name = "address",value = "人们地址",required = true,paramType = "字符串",dataType = "字符串"),
            @ApiImplicitParam(name = "age",value = "人们年龄",required = true,paramType = "整数",dataType = "整数"),
            @ApiImplicitParam(name = "createTime",value = "创建时间",required = true,paramType = "日期",dataType = "日期")
    })
    @PostMapping("addPeople2")
    public ResultObj addPeople2(@RequestBody People people) {
        // @RequestBody验证前端所有数据非空的同时要求必须提交json格式的数据
        System.out.println(people);
        return new ResultObj(200,"添加成功");
    }

    /**
     * 删除人们
     * @param id 人们Id
     * @return
     */
    @ApiOperation(value = "删除人们")
    @DeleteMapping("deletePeople")
    public ResultObj deletePeople(@RequestParam("id") Integer id) {
        // 加了@RequestParam之后可以解决调试时验证问题
        System.out.println(id);
        return new ResultObj(200,"删除成功");
    }

    /**
     * 修改人们
     * @param people
     * @return
     */
    @ApiOperation(value = "修改人们")
    @PostMapping("updatePeople")
    public ResultObj updatePeople(@RequestBody People people) {
        // @RequestBody验证前端所有数据非空的，同时要求必须提交json格式的数据
        System.out.println(people);
        return new ResultObj(200,"修改成功");
    }


    /**
     * 根据Id查询人们信息
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID查询人们",consumes = "根据ID查询人们")
    @GetMapping("getPeopleById")
    public People getPeopleById(@RequestParam("id")Integer id) {
        // 加了@RequestParam之后，可以解决调试时验证问题
        return new People(id, "小明","广州天河区",19,new Date());
    }

    @ApiOperation(value = "查询人们所有数据",consumes = "查询人们所有数据")
    @GetMapping("getPeopleAll")
    public List<People> getPeopleAll() {
        List<People> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            list.add(new People(i,"小高"+i,"广东深圳",18+i,new Date()));
        }
        return list;
    }
}
